package com.lsh.payment.core.strategy.payment;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 支付策略工厂
 * Project Name: lsh-payment
 *
 * @author peter
 * @date 16/10/30
 * 北京链商电子商务有限公司
 * Package
 * desc:
 */
public class PayStrategyFactory {

    private static Map<Integer, PayStrategy> strategyMap = new ConcurrentHashMap<>();

    private PayStrategyFactory() {
    }

    private static class InstanceHolder {
        public static PayStrategyFactory instance = new PayStrategyFactory();
    }

    public static PayStrategyFactory getInstance() {
        return InstanceHolder.instance;
    }

    /**
     * 实现自动注册
     * @param strategyNo
     * @param strategyInfo
     */
    public static void register(int strategyNo, PayStrategy strategyInfo) {
        strategyMap.put(strategyNo, strategyInfo);
    }

    /**
     * 获取具体策略
     * @param type
     * @return
     */
    public PayStrategy creator(Integer type) {
        return strategyMap.get(type);
    }
}
